package com.pro.controller;

import com.pro.pojo.JsUserCoupon;
import com.pro.pojo.JsonData;
import com.pro.service.JsUserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.logging.Logger;

@Controller
@RequestMapping("/JsUserCoupon")
public class JsUserCouponController {
    @Autowired
    JsUserCouponService jucs;
    @RequestMapping(value = "/getAllJsUserCoupon")
    @ResponseBody
    public JsonData getAllJsUserCoupon(JsUserCoupon param){
        List<JsUserCoupon> allJsUserCoupon = jucs.getAllJsUserCoupon(param);

        return allJsUserCoupon != null ?JsonData.buildSuccess(allJsUserCoupon):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/updateJsUserCouponUsedUsedState")
    @ResponseBody
    public JsonData updateJsUserCouponUsedUsedState(Integer couponId) {
        boolean b = jucs.updateJsUserCouponUsedUsedState(couponId);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/deleteByIdJsUserCoupon")
    @ResponseBody
    public JsonData deleteByIdJsUserCoupon(Integer couponId){
        Logger logger= Logger.getGlobal();
        boolean b = jucs.deleteByIdJsUserCoupon(couponId);
        logger.info("这是个日志输出");
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/updateByIdOnline")
    @ResponseBody
    public JsonData updateByIdOnline(JsUserCoupon param){
        boolean b = jucs.updateByIdOnline(param);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/selectAllcouponName")
    @ResponseBody
    public JsonData selectAllcouponName(){
        List<JsUserCoupon> jsUserCoupons = jucs.selectAllcouponName();
        return jsUserCoupons!=null?JsonData.buildSuccess(jsUserCoupons):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/selectRetrieval")
    @ResponseBody
    public JsonData selectRetrieval(JsUserCoupon param){
        List<JsUserCoupon> jsUserCoupons = jucs.selectRetrieval(param);
        return jsUserCoupons!=null?JsonData.buildSuccess(jsUserCoupons):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/addJsUserCoupon")
    @ResponseBody
    public JsonData addJsUserCoupon(JsUserCoupon param){
        boolean b = jucs.addJsUserCoupon(param);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/selectByIdJsUserCoupon")
    @ResponseBody
    public JsonData selectByIdJsUserCoupon(Integer couponCode){
        JsUserCoupon jsUserCoupon = jucs.selectByIdJsUserCoupon(couponCode);
        return jsUserCoupon != null?JsonData.buildSuccess(jsUserCoupon):JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/addDictData")
    @ResponseBody
    public JsonData addDictData(JsUserCoupon dictData){
        boolean b = jucs.addDictData(dictData);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/getJsUserCouponById")
    @ResponseBody
    public JsonData getJsUserCouponById(JsUserCoupon jsUserCoupon){
        JsUserCoupon jsUserCouponById = jucs.getJsUserCouponById(jsUserCoupon);
        return jsUserCouponById != null?JsonData.buildSuccess(jsUserCouponById):JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/updateJsUserCouponUsed")
    @ResponseBody
    public JsonData updateJsUserCouponUsed(JsUserCoupon jsUserCoupon){
        boolean b = jucs.updateJsUserCouponUsed(jsUserCoupon);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器出错了");
    }
    //查询订单有没有使用优惠卷
    @RequestMapping(value = "/getUserCouponPrice")
    @ResponseBody
    public JsonData getUserCouponPrice(Integer orderId){
        String userCouponPrice = jucs.getUserCouponPrice(orderId);
        return JsonData.buildSuccess(userCouponPrice);
    }
}
